# -*- coding: utf-8 -*-
# @FileName :conftest.py
# @Time :2024-01-28 18:53
# author: 小燕子

import pytest
import jsonpath
from ..Package.database import Sql
@pytest.fixture(autouse=True)
def headers():
    return {
        "content-type":"application/json"
    }

@pytest.fixture(autouse=True)
def params():
    return {
        "s": "api/user/login",
        "application": "app",
        "application_client_type": "weixin"
    }

@pytest.fixture(autouse=True)
def conf():
    return {
        "method" : "post",
        "url" : "http://shop-xo.hctestedu.com:80/index.php",
    }

@pytest.fixture(autouse=True)
def assert_operate():
    def func(assert_data, response_data):
        for k,v in assert_data.items():
            data = jsonpath.jsonpath(response_data,k)[0]
            assert data == v,f'业务断言失败，实际拿到的数据：{data}，预期的数据是：{v}'
        print("业务断言成功")
    return func # 引用

@pytest.fixture(autouse=True)
def assert_sql_data():
    def func(expect_value, assert_data):
        data = Sql().execute(assert_data["dql"]).fetchone()
        expect_data = jsonpath.jsonpath(data,assert_data["jsonpath"])[0]
        assert expect_data == expect_value,f"数据断言失败，实际拿到的数据是{data},预期的数据是{assert_data}"
        print("数据断言成功")
    return func